package com.huynhchihieu.domain;

import java.io.Serializable;

import javax.persistence.*;

import com.huynhchihieu.springsecurity.dto.RoleEnum;
import com.huynhchihieu.springsecurity.dto.SocialMediaService;

import java.util.List;


/**
 * The persistent class for the domainuser database table.
 * 
 */
@Entity
@Table(name="domainuser")
@NamedQuery(name="Domainuser.findAll", query="SELECT d FROM Domainuser d")
public class Domainuser implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="user_id", unique=true, nullable=false)
	private int userId;

	@Column(name="login", length=45)
	private String login;

	@Column(length=225)
	private String password;
	
	@Column(name="user_email", nullable=true, length=225)
	private String email;
	
	@Column(length=225)
	private String firstname;
	
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public SocialMediaService getSignInProvider() {
		return signInProvider;
	}

	public void setSignInProvider(SocialMediaService signInProvider) {
		this.signInProvider = signInProvider;
	}

	public RoleEnum getRole() {
		return role;
	}

	public void setRole(RoleEnum role) {
		this.role = role;
	}
	@Column(length=225)
	private String lastname;

	//bi-directional many-to-one association to UserRole
	@OneToMany(mappedBy="domainuser")
	private List<UserRole> userRoles;
	
	@Enumerated(EnumType.STRING)
    @Column(name = "sign_in_provider", length = 225)
    private SocialMediaService signInProvider;
	
	@Enumerated(EnumType.STRING)
    @Column(name = "role", length = 225, nullable = true)
    private RoleEnum role;

	public Domainuser() {
	}

	public int getUserId() {
		return this.userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public String getLogin() {
		return this.login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public List<UserRole> getUserRoles() {
		return this.userRoles;
	}

	public void setUserRoles(List<UserRole> userRoles) {
		this.userRoles = userRoles;
	}

	public UserRole addUserRole(UserRole userRole) {
		getUserRoles().add(userRole);
		userRole.setDomainuser(this);

		return userRole;
	}

	public UserRole removeUserRole(UserRole userRole) {
		getUserRoles().remove(userRole);
		userRole.setDomainuser(null);

		return userRole;
	}
	public static Builder getBuilder() {
        return new Builder();
    }
	//The constructor and getters are omitted for the sake of clarity
    public static class Builder {
 
        private Domainuser user;
 
        public Builder() {
            user = new Domainuser();
            user.role = RoleEnum.ROLE_USER;
        }
 
        // using login instead of email
        public Builder email(String email) {
            user.email = email;
            return this;
        }
 
        public Builder firstName(String firstName) {
            user.firstname = firstName;
            return this;
        }
 
        public Builder lastName(String lastName) {
            user.lastname = lastName;
            return this;
        }
 
        public Builder password(String password) {
            user.password = password;
            return this;
        }
 
        public Builder signInProvider(SocialMediaService signInProvider) {
            user.signInProvider = signInProvider;
            return this;
        }
 
        public Domainuser build() {
            return user;
        }
    }

}